<template>
  <ContentWrap>
    <!-- 搜索工作栏 -->
    <el-form
        class="-mb-15px"
        :model="queryParams"
        ref="queryFormRef"
        :inline="true"
        label-width="68px"
    >
      <el-form-item label="登记时间" prop="registerTime">
        <el-date-picker
            v-model="queryParams.registerTime"
            value-format="YYYY-MM-DD HH:mm:ss"
            type="daterange"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
            class="!w-240px"
        />
      </el-form-item>
      <el-form-item label="返款时间" prop="refundTime">
        <el-date-picker
          v-model="queryParams.refundTime"
          value-format="YYYY-MM-DD HH:mm:ss"
          type="daterange"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
          class="!w-240px"
        />
      </el-form-item>
      <el-form-item label="店铺" prop="shopId">
        <select-basic-shop v-model="queryParams.shopId"/>
      </el-form-item>
      <el-form-item>
        <el-button @click="handleQuery">
          <Icon icon="ep:search" class="mr-5px"/>
          搜索
        </el-button>
        <el-button @click="resetQuery">
          <Icon icon="ep:refresh" class="mr-5px"/>
          重置
        </el-button>
      </el-form-item>
    </el-form>
  </ContentWrap>

  <ContentWrap>
    <el-table
        row-key="id"
        v-loading="loading"
        :data="list"
        :stripe="true"
        :default-sort="{prop: 'score', order: 'descending'}"
    >
      <el-table-column label="排名" type="index" width="80"/>
      <el-table-column label="店铺名称" align="center" prop="shopName"/>
      <el-table-column label="店铺id" align="center" prop="shopId"/>
      <el-table-column label="返款金额" align="center" prop="refundMoney" sortable>
        <template #default="scope">
          <el-tag>{{ scope.row.refundMoney.toFixed(2) }}</el-tag>
        </template>
      </el-table-column>

      <el-table-column label="订单金额" align="center" prop="orderMoney" sortable>
        <template #default="scope">
          <el-tag>{{ scope.row.orderMoney.toFixed(2) }}</el-tag>
        </template>
      </el-table-column>

      <el-table-column label="佣金金额" align="center" prop="businessMoney" sortable>
        <template #default="scope">
          <el-tag>{{ scope.row.businessMoney.toFixed(2) }}</el-tag>
        </template>
      </el-table-column>

      <el-table-column label="礼品成本" align="center" prop="giftCost" sortable>
        <template #default="scope">
          <el-tag>{{ scope.row.giftCost.toFixed(2) }}</el-tag>
        </template>
      </el-table-column>
    </el-table>
  </ContentWrap>

</template>


<script setup>

import {ref} from "vue";
import {BusinessApi} from '@/api/business/operation/business/order'

const loading = ref(true) // 列表的加载中
const queryFormRef = ref() // 搜索的表单
const list = ref([])
const queryParams = reactive({
  shopId: null,
  registerTime: []
})

const getList = async () => {
  loading.value = true
  try {
    const data = await BusinessApi.getBusinessSum(queryParams)
    console.log(data)
    list.value = data
  } finally {
    loading.value = false
  }
}


const handleQuery = () => {
  queryParams.pageNo = 1
  getList()
}

const resetQuery = () => {
  queryFormRef.value.resetFields()
  handleQuery()
}

/** 初始化 **/
onMounted(() => {
  getList()
})

</script>
